//
//  CertificationManageViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/7.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "CertificationManageViewModel.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "CertificationTopViewTableViewCell.h"
#import "CertificationListTableViewCell.h"
#import "CertificationFootView.h"

@interface CertificationManageViewModel ()<UITableViewDelegate,UITableViewDataSource>{
    CertificationType cer_type;
    NSArray * leftTitleArr;
}

@end

@implementation CertificationManageViewModel

-(instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView theCerType:(CertificationType)c_type{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        leftTitleArr = @[@"企业名称",@"营业执照注册号",@"运营者姓名",@"运营者身份证号"];
        cer_type = c_type;
        tableView.mj_footer.hidden = YES;
        tableView.mj_header.hidden = YES;
        tableView.dataSource = self;
        tableView.delegate = self;
        [tableView registerClass:[NoDataFootTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        if (c_type == CertificationType_Failure) {
            tableView.tableFooterView = [self createFootView];
        }
        [superView addSubview:tableView];
    }
    return self;
}

-(UIView *)createFootView{
    CertificationFootView * footView = [[CertificationFootView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(110))];
    return footView;
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (cer_type == CertificationType_IntheRever) {
        return 1;
    }else{
        return 2;
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else{
        return 4;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (cer_type == CertificationType_Failure) {
            return kHeightProportion_In_iPhoneTriploid(205);
        }else{
            return kHeightProportion_In_iPhoneTriploid(178);
        }
    }else{
        return kHeightProportion_In_iPhoneTriploid(44);
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BaseTableViewCell * cell;
    if (indexPath.section == 0) {
        CertificationTopViewTableViewCell * cell_topView = [CertificationTopViewTableViewCell cellWithTableView:tableView];
        cell_topView.cellCertype = cer_type;
        cell = cell_topView;
    }else{
        CertificationListTableViewCell * cell_list = [CertificationListTableViewCell cellWithTableView:tableView];
        cell_list.cerLeftStr = leftTitleArr[indexPath.row];
        cell_list.cerRightStr = @"北京泽人合物资有限公司";
        [cell_list setSepartionLineWith:lineModel_Half];
        cell = cell_list;
    }
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NoDataFootTableViewHeaderFooterView * headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return kHeightProportion_In_iPhoneTriploid(10);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NoDataFootTableViewHeaderFooterView * footView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return footView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}


@end
